import%20marimo%0A%0A__generated_with%20%3D%20%220.13.15%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22%2C%20app_title%3D%22SBI%20SED%20Fitting%22)%0A%0Awith%20app.setup%3A%0A%20%20%20%20%23%20Initialization%20code%20that%20runs%20before%20all%20other%20cells%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20altair%20as%20alt%0A%20%20%20%20import%20pandas%20as%20pd%0A%20%20%20%20import%20sbi%0A%20%20%20%20import%20torch%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20from%20astropy.table%20import%20Table%0A%20%20%20%20from%20ltu_ili_testing%20import%20SBI_Fitter%2C%20create_uncertainity_models_from_EPOCHS_cat%0A%20%20%20%20from%20typing%20import%20Dict%2C%20List%0A%20%20%20%20import%20numpy%20as%20np%0A%0A%20%20%20%20device%20%3D%20%22cuda%22%20if%20torch.cuda.is_available()%20else%20%22cpu%22%0A%20%20%20%20alt.data_transformers.enable(%22vegafusion%22)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(rf%22%22%22%23%23%23%20Running%20SBI%20on%20device%3A%7Bdevice%7D%20with%20torch%20%7Btorch.__version__%7D%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(r%22%22%22Firstly%20we%20setup%20empirical%20noise%20models%20to%20estimate%20flux%20uncertainity%20from%20real%20data%20which%20we%20can%20use%20to%20scatter%20the%20photometry.%20There%20are%20quite%20a%20few%20subtlites%20in%20how%20these%20flux%20uncertanties%20are%20estimated%20and%20scattered%2C%20and%20how%20upper%20limits%20are%20handled.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20file%20%3D%20%22%2Fhome%2Ftharvey%2FDownloads%2FJADES-Deep-GS_MASTER_Sel-f277W%2Bf356W%2Bf444W_v9_loc_depth_masked_10pc_EAZY_matched_selection_ext_src_UV.fits%22%0A%20%20%20%20table%20%3D%20Table.read(file)%0A%20%20%20%20bands%20%3D%20%5Bi.split(%22_%22)%5B-1%5D%20for%20i%20in%20table.colnames%20if%20i.startswith(%22loc_depth%22)%5D%20%20%23%20remove%20F606W%0A%20%20%20%20new_band_names%20%3D%20%5B%22HST%2FACS_WFC.F606W%22%5D%20%2B%20%5Bf%22JWST%2FNIRCam.%7Bband.upper()%7D%22%20for%20band%20in%20bands%5B1%3A%5D%5D%0A%0A%20%20%20%20names%20%3D%20%5Bname%20for%20name%20in%20table.colnames%20if%20len(table%5Bname%5D.shape)%20%3C%3D%201%5D%0A%20%20%20%20%23%20df%20%3D%20table%5Bnames%5D.to_pandas()%0A%0A%20%20%20%20empirical_noise_models%20%3D%20create_uncertainity_models_from_EPOCHS_cat(%0A%20%20%20%20%20%20%20%20file%2C%20bands%5B1%3A%5D%2C%20new_band_names%5B1%3A%5D%2C%20plot%3DFalse%0A%20%20%20%20)%0A%20%20%20%20return%20bands%2C%20empirical_noise_models%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(bands)%3A%0A%20%20%20%20mo.md(rf%22%22%22Created%20noise%20models%20for%20%7B%22%2C%20%22.join(bands)%7D%20(%7Blen(bands)%7D%20filters)%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(empirical_noise_models)%3A%0A%20%20%20%20model_name%20%3D%20%22BPASS_Chab_DelayedExpSFH_0.01_z_12_CF00_v1%22%0A%20%20%20%20grid_path%20%3D%20%22%2Fhome%2Ftharvey%2Fwork%2Foutput%2Fgrid_BPASS_DelayedExponential_SFH_0.01_z_12_logN_5.7_Chab_CF00_v1.hdf5%22%0A%0A%0A%20%20%20%20empirical_model_fitter%20%3D%20SBI_Fitter.init_from_hdf5(model_name%2C%20grid_path%2C%20return_output%3DFalse)%0A%0A%20%20%20%20unused_filters%20%3D%20%5B%0A%20%20%20%20%20%20%20%20filt%0A%20%20%20%20%20%20%20%20for%20filt%20in%20empirical_model_fitter.raw_photometry_names%0A%20%20%20%20%20%20%20%20if%20filt%20not%20in%20list(empirical_noise_models.keys())%0A%20%20%20%20%5D%0A%20%20%20%20return%20empirical_model_fitter%2C%20grid_path%2C%20model_name%2C%20unused_filters%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(grid_path%2C%20model_name)%3A%0A%20%20%20%20mo.md(rf%22%22%22Created%20SBI%20Fitter%20with%20name%3A%20%7Bmodel_name%7D%20from%20Synthesizer%20model%20library%20%7Bgrid_path.split(%22%2F%22)%5B-1%5D%7D%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20run_button%20%3D%20mo.ui.run_button(label%3D%22Click%20to%20create%20feature%20array%20from%20loaded%20photometry.%22)%0A%20%20%20%20run_button%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(empirical_model_fitter%2C%20empirical_noise_models%2C%20unused_filters)%3A%0A%20%20%20%20%23%20mo.stop(not%20run_button.value%2C%20mo.md(%22Click%20%F0%9F%91%86%20to%20create%20feature%20array.%22))%0A%20%20%20%20with%20mo.redirect_stdout()%20and%20mo.redirect_stderr()%3A%0A%20%20%20%20%20%20%20%20arr%20%3D%20empirical_model_fitter.create_feature_array_from_raw_photometry(%0A%20%20%20%20%20%20%20%20%20%20%20%20extra_features%3D%5B%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20normalize_method%3DNone%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20include_errors_in_feature_array%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20scatter_fluxes%3D1%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20empirical_noise_models%3Dempirical_noise_models%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20photometry_to_remove%3Dunused_filters%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20norm_mag_limit%3D40%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20drop_dropouts%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20drop_dropout_fraction%3D0.5%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20return%20(arr%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(arr%2C%20empirical_model_fitter)%3A%0A%20%20%20%20_%20%3D%20arr%0A%20%20%20%20if%20empirical_model_fitter.feature_array%20is%20not%20None%3A%0A%20%20%20%20%20%20%20%20fitter_df%20%3D%20empirical_model_fitter.create_dataframe()%0A%20%20%20%20%20%20%20%20mo.output.append(fitter_df)%0A%20%20%20%20return%20(fitter_df%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(empirical_model_fitter%2C%20fitter_df)%3A%0A%20%20%20%20def%20create_histogram_chart(%0A%20%20%20%20%20%20%20%20_df%3A%20pd.DataFrame%2C%20column%3A%20str%2C%20width%3A%20int%20%3D%20240%2C%20height%3A%20int%20%3D%20100%0A%20%20%20%20)%20-%3E%20alt.Chart%3A%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20Creates%20an%20Altair%20histogram%20chart%20with%20a%20prominent%20title%20and%20formatted%20x-axis%20labels.%0A%0A%20%20%20%20%20%20%20%20Args%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20_df%3A%20The%20pandas%20DataFrame%20containing%20the%20data.%0A%20%20%20%20%20%20%20%20%20%20%20%20column%3A%20The%20name%20of%20the%20column%20to%20plot.%0A%20%20%20%20%20%20%20%20%20%20%20%20width%3A%20The%20width%20of%20the%20chart.%0A%20%20%20%20%20%20%20%20%20%20%20%20height%3A%20The%20height%20of%20the%20chart.%0A%0A%20%20%20%20%20%20%20%20Returns%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20An%20Altair%20Chart%20object.%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20chart%20%3D%20(%0A%20%20%20%20%20%20%20%20%20%20%20%20alt.Chart(_df)%0A%20%20%20%20%20%20%20%20%20%20%20%20.mark_bar(binSpacing%3D1)%0A%20%20%20%20%20%20%20%20%20%20%20%20.encode(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20x%3Dalt.X(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20field%3Dcolumn%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20type%3D%22quantitative%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20bin%3Dalt.Bin(maxbins%3D40)%2C%20%20%23%20Adjust%20number%20of%20bins%20for%20clarity%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20axis%3Dalt.Axis(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20title%3Dcolumn%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20labels%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20labelAngle%3D0%2C%20%20%23%20Ensure%20labels%20are%20horizontal%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20format%3D%22~s%22%2C%20%20%23%20Use%20SI-prefix%20format%20for%20numbers%20(e.g.%2C%201.5k%2C%202M)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20You%20can%20also%20use%20'd'%20for%20integers%20or%20'.2f'%20for%20floats.%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20y%3Dalt.Y(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22count()%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20type%3D%22quantitative%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20title%3D%22Number%20of%20records%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20tooltip%3D%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20alt.Tooltip(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20column%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20type%3D%22quantitative%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20bin%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20title%3Dcolumn%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20format%3D%22%2C.2f%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20alt.Tooltip(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22count()%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20type%3D%22quantitative%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20format%3D%22%2C.0f%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20title%3D%22Number%20of%20records%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20.properties(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20title%3Dalt.TitleParams(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20text%3Df%22Distribution%20of%20%7Bcolumn%7D%22%2C%20%20%23%20More%20descriptive%20title%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20anchor%3D%22middle%22%2C%20%20%23%20Center%20the%20title%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20width%3Dwidth%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20height%3Dheight%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20return%20chart%0A%0A%0A%20%20%20%20_col%20%3D%20empirical_model_fitter.feature_names%0A%20%20%20%20_ncharts%20%3D%20len(_col)%0A%20%20%20%20_nrows%20%3D%20int(np.ceil(_ncharts%20%2F%203))%0A%0A%20%20%20%20_k%20%3D%201%0A%0A%20%20%20%20rows%20%3D%20%5B%5D%0A%20%20%20%20for%20_i%20in%20range(_nrows)%3A%0A%20%20%20%20%20%20%20%20_row%20%3D%20mo.hstack(%0A%20%20%20%20%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mo.vstack(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mo.md(empirical_model_fitter.feature_names%5B_k%20%2B%20_l%5D)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20create_histogram_chart(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20fitter_df%2C%20empirical_model_fitter.feature_names%5B_k%20%2B%20_l%5D.replace(%22.%22%2C%20%22%5C.%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20for%20_l%20in%20range(3)%0A%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20%20%20%20%20rows.append(_row)%0A%20%20%20%20%20%20%20%20_k%20%2B%3D%202%0A%0A%0A%20%20%20%20mo.vstack(rows)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(arr%2C%20empirical_model_fitter)%3A%0A%20%20%20%20_%20%3D%20arr%0A%20%20%20%20flux_limit_slider%20%3D%20mo.ui.slider(%0A%20%20%20%20%20%20%20%20label%3D%22Mag%20Limit%22%2C%0A%20%20%20%20%20%20%20%20value%3D32%2C%0A%20%20%20%20%20%20%20%20start%3Dnp.nanmin(empirical_model_fitter.feature_array%5B%3A%2C%20%3A9%5D)%2C%0A%20%20%20%20%20%20%20%20stop%3Dnp.nanmax(empirical_model_fitter.feature_array%5B%3A%2C%20%3A9%5D)%2C%0A%20%20%20%20)%0A%20%20%20%20mo.hstack(%5Bflux_limit_slider%5D)%0A%20%20%20%20return%20(flux_limit_slider%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(empirical_model_fitter%2C%20flux_limit_slider)%3A%0A%20%20%20%20n_below_1sig%20%3D%20np.sum(%0A%20%20%20%20%20%20%20%20np.all(empirical_model_fitter.feature_array%5B%3A%2C%20%3A9%5D%20%3E%20flux_limit_slider.value%2C%20axis%3D1)%2C%20axis%3D0%0A%20%20%20%20)%0A%20%20%20%20mo.output.append(%0A%20%20%20%20%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Let's%20check%20roughly%20what%20fraction%20of%20our%20test%20samples%20are%20below%20our%20detection%20limit%20for%20this%20noise%20model.%22%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20)%0A%20%20%20%20mo.output.append(%0A%20%20%20%20%20%20%20%20mo.callout(%0A%20%20%20%20%20%20%20%20%20%20%20%20f%22%7Bn_below_1sig%7D%20rows%20of%20feature%20array%20have%20flux%20%3E%20%7Bflux_limit_slider.value%7D%20in%20all%20bands.%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22danger%22%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(fitter_df)%3A%0A%20%20%20%20text%20%3D%20mo.md(%22We%20can%20see%20what%20%24f(%5Csigma)%24%20looks%20like%22)%0A%20%20%20%20dropdown_x%20%3D%20mo.ui.dropdown(options%3Dfitter_df.columns%2C%20label%3D%22x%22%2C%20value%3D%22JWST%2FNIRCam.F444W%22)%0A%20%20%20%20dropdown_y%20%3D%20mo.ui.dropdown(options%3Dfitter_df.columns%2C%20label%3D%22y%22%2C%20value%3D%22unc_JWST%2FNIRCam.F444W%22)%0A%0A%20%20%20%20mo.vstack(%5Btext%2C%20dropdown_x%2C%20dropdown_y%5D)%0A%20%20%20%20return%20dropdown_x%2C%20dropdown_y%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(dropdown_x%2C%20dropdown_y%2C%20fitter_df)%3A%0A%20%20%20%20fig%2C%20ax%20%3D%20plt.subplots(dpi%3D100)%0A%20%20%20%20ax.scatter(fitter_df%5Bdropdown_x.value%5D%2C%20fitter_df%5Bdropdown_y.value%5D%2C%20s%3D1)%0A%20%20%20%20ax.set_xlabel(dropdown_x.value)%0A%20%20%20%20ax.set_ylabel(dropdown_y.value)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20Now%20we%20can%20setup%20and%20run%20the%20SBI%20model%20itself.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20_model_options_list%3A%20Dict%5Bstr%2C%20List%5Bstr%5D%5D%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22sbi%22%3A%20%5B%22mdn%22%2C%20%22maf%22%2C%20%22nsf%22%2C%20%22made%22%2C%20%22linear%22%2C%20%22mlp%22%2C%20%22resnet%22%5D%2C%0A%20%20%20%20%20%20%20%20%22lampe%22%3A%20%5B%22mdn%22%2C%20%22maf%22%2C%20%22nsf%22%2C%20%22ncsf%22%2C%20%22cnf%22%2C%20%22nice%22%2C%20%22sospf%22%2C%20%22gf%22%2C%20%22naf%22%5D%2C%0A%20%20%20%20%7D%0A%20%20%20%20model_options%3A%20Dict%5Bstr%2C%20Dict%5Bstr%2C%20str%5D%5D%20%3D%20%7B%0A%20%20%20%20%20%20%20%20backend%3A%20%7Bmodel%3A%20model%20for%20model%20in%20models%7D%20for%20backend%2C%20models%20in%20_model_options_list.items()%0A%20%20%20%20%7D%0A%20%20%20%20%23%20---%20Cell%204%3A%20Pre-instantiate%20all%20UI%20components%20---%0A%20%20%20%20%23%20To%20preserve%20state%20when%20n_nets%20changes%2C%20we%20create%20all%20possible%20UI%20elements%0A%20%20%20%20%23%20upfront%20and%20store%20them.%20Marimo%20will%20only%20display%20the%20active%20ones.%0A%0A%0A%20%20%20%20%23%20---%20Cell%204%3A%20Pre-instantiate%20all%20UI%20components%20(Corrected%20for%20Independence)%20---%0A%0A%20%20%20%20%23%20FIX%3A%20To%20ensure%20each%20network%20has%20independent%20controls%2C%20the%20UI%20elements%0A%20%20%20%20%23%20(mo.ui.slider%2C%20mo.ui.dropdown)%20must%20be%20created%20*inside*%20the%20loop.%0A%20%20%20%20%23%20This%20creates%20new%2C%20distinct%20objects%20for%20each%20network's%20control%20dictionary.%0A%0A%20%20%20%20MAX_NETS%20%3D%206%0A%20%20%20%20network_controls%20%3D%20%5B%5D%0A%0A%0A%20%20%20%20for%20_%20in%20range(MAX_NETS)%3A%0A%20%20%20%20%20%20%20%20%23%20Each%20iteration%20creates%20brand%20new%20UI%20objects%0A%20%20%20%20%20%20%20%20network_controls.append(%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22model_type%22%3A%20mo.ui.dropdown(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20options%3Dmodel_options%5B%22sbi%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20value%3D%22mdn%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20label%3D%22Model%20Type%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22hidden_features%22%3A%20mo.ui.slider(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20start%3D10%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20stop%3D256%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20step%3D1%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20value%3D50%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20label%3D%22Hidden%20Features%3A%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20show_value%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22value_slider%22%3A%20mo.ui.slider(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20start%3D1%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20stop%3D20%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20step%3D1%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20value%3D4%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20label%3D%22Num%20Transforms%2FComponents%3A%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20show_value%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20)%0A%0A%0A%20%20%20%20%23%20Create%20the%20initial%20state%20for%20all%20possible%20networks%0A%20%20%20%20initial_configs%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22model_type%22%3A%20%22mdn%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22hidden_features%22%3A%2050%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22value%22%3A%204%2C%20%20%23%20Represents%20num_components%20or%20num_transforms%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20for%20_%20in%20range(MAX_NETS)%0A%20%20%20%20%5D%0A%0A%20%20%20%20%23%20Initialize%20the%20state%20and%20get%20the%20setter%20function%0A%20%20%20%20configs%2C%20set_configs%20%3D%20mo.state(initial_configs%2C%20allow_self_loops%3DFalse)%0A%0A%20%20%20%20%23%20Initialize%20the%20state%20and%20get%20the%20setter%20function%0A%20%20%20%20%23%20These%20handler%20functions%20are%20called%20by%20the%20UI%20elements'%20on_change%20event.%0A%0A%0A%20%20%20%20def%20update_config_value(key%3A%20str%2C%20value%2C%20index%3A%20int)%20-%3E%20None%3A%0A%20%20%20%20%20%20%20%20%22%22%22A%20generic%20handler%20to%20update%20any%20key%20for%20a%20given%20network.%22%22%22%0A%20%20%20%20%20%20%20%20%23%20It's%20good%20practice%20to%20work%20on%20a%20copy%20of%20the%20state%0A%20%20%20%20%20%20%20%20current_configs%20%3D%20list(configs())%0A%20%20%20%20%20%20%20%20current_configs%5Bindex%5D%5Bkey%5D%20%3D%20value%0A%20%20%20%20%20%20%20%20set_configs(current_configs)%0A%20%20%20%20return%20configs%2C%20model_options%2C%20network_controls%2C%20update_config_value%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20backend%2C%0A%20%20%20%20configs%2C%0A%20%20%20%20model_options%3A%20Dict%5Bstr%2C%20Dict%5Bstr%2C%20str%5D%5D%2C%0A%20%20%20%20n_nets%2C%0A%20%20%20%20update_config_value%2C%0A)%3A%0A%20%20%20%20%23%20---%20Cell%205%3A%20Dynamically%20build%20and%20display%20the%20network%20configuration%20UI%20(Corrected%20for%20Reactivity)%20---%0A%0A%20%20%20%20%23%20FIX%3A%20All%20logic%20for%20updating%20and%20displaying%20the%20tabs%20MUST%20be%20in%20the%20same%0A%20%20%20%20%23%20cell.%20This%20allows%20Marimo%20to%20correctly%20track%20that%20this%20cell%20needs%20to%0A%20%20%20%20%23%20re-run%20when%20%60backend%60%20or%20any%20of%20the%20%60network_controls%60%20UI%20elements%20change.%0A%0A%20%20%20%20mo.md(%22---%22)%0A%20%20%20%20mo.md(%22%23%23%20Network%20Ensemble%20Configuration%22)%0A%0A%0A%20%20%20%20%23%20First%2C%20update%20the%20state%20of%20all%20dropdowns%20based%20on%20the%20global%20backend%0A%20%20%20%20_backend_value%20%3D%20backend.value%0A%20%20%20%20num_networks%3A%20int%20%3D%20n_nets.value%0A%20%20%20%20tabs%20%3D%20%7B%7D%0A%0A%20%20%20%20%23%20Get%20the%20current%20backend%20to%20populate%20dropdown%20options%0A%20%20%20%20available_models%20%3D%20model_options%5Bbackend.value%5D%0A%0A%20%20%20%20for%20_i%20in%20range(num_networks)%3A%0A%20%20%20%20%20%20%20%20%23%20Get%20the%20config%20for%20this%20specific%20network%20from%20the%20central%20state%0A%20%20%20%20%20%20%20%20net_config%20%3D%20configs()%5B_i%5D%0A%0A%20%20%20%20%20%20%20%20%23%20Create%20UI%20elements%20on-the-fly%20based%20on%20the%20current%20state%0A%20%20%20%20%20%20%20%20model_type_dd%20%3D%20mo.ui.dropdown(%0A%20%20%20%20%20%20%20%20%20%20%20%20options%3Davailable_models%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20value%3Dnet_config%5B%22model_type%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20label%3D%22Model%20Type%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%23%20When%20this%20dropdown%20changes%2C%20call%20the%20handler%20for%20the%20correct%20index%20%60i%60%0A%20%20%20%20%20%20%20%20%20%20%20%20on_change%3Dlambda%20value%2C%20index%3D_i%3A%20update_config_value(%22model_type%22%2C%20value%2C%20index)%2C%0A%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20%20%20%20%20hidden_features_slider%20%3D%20mo.ui.slider(%0A%20%20%20%20%20%20%20%20%20%20%20%20start%3D10%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20stop%3D256%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20value%3Dnet_config%5B%22hidden_features%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20label%3D%22Hidden%20Features%3A%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20show_value%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20on_change%3Dlambda%20value%2C%20index%3D_i%3A%20update_config_value(%22hidden_features%22%2C%20value%2C%20index)%2C%0A%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20%20%20%20%20value_slider%20%3D%20mo.ui.slider(%0A%20%20%20%20%20%20%20%20%20%20%20%20start%3D1%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20stop%3D20%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20value%3Dnet_config%5B%22value%22%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20show_value%3DTrue%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20on_change%3Dlambda%20value%2C%20index%3D_i%3A%20update_config_value(%22value%22%2C%20value%2C%20index)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20label%3D%22Num%20Components%2FTransforms%3A%22%2C%0A%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20%20%20%20%20%23%20Build%20the%20list%20of%20elements%20to%20show%20in%20the%20tab%0A%20%20%20%20%20%20%20%20current_model%3A%20str%20%3D%20net_config%5B%22model_type%22%5D%0A%20%20%20%20%20%20%20%20ui_elements%20%3D%20%5Bmodel_type_dd%5D%0A%0A%20%20%20%20%20%20%20%20if%20current_model%20%3D%3D%20%22mdn%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20value_slider.label%20%3D%20%22Num%20Components%22%0A%20%20%20%20%20%20%20%20%20%20%20%20ui_elements.extend(%5Bhidden_features_slider%2C%20value_slider%5D)%0A%20%20%20%20%20%20%20%20elif%20current_model%20in%20%5B%22maf%22%2C%20%22nsf%22%2C%20%22made%22%2C%20%22ncsf%22%2C%20%22cnf%22%2C%20%22gf%22%2C%20%22sospf%22%2C%20%22naf%22%2C%20%22unaf%22%5D%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20value_slider.label%20%3D%20%22Num%20Transforms%22%0A%20%20%20%20%20%20%20%20%20%20%20%20ui_elements.extend(%5Bhidden_features_slider%2C%20value_slider%5D)%0A%20%20%20%20%20%20%20%20elif%20current_model%20in%20%5B%22mlp%22%2C%20%22resnet%22%5D%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20ui_elements.append(hidden_features_slider)%0A%0A%20%20%20%20%20%20%20%20tabs%5Bf%22Network%20%7B_i%20%2B%201%7D%22%5D%20%3D%20mo.vstack(ui_elements)%0A%0A%0A%20%20%20%20%22%22%22%20%20%20%20for%20i%20in%20range(MAX_NETS)%3A%0A%20%20%20%20controls%20%3D%20network_controls%5Bi%5D%0A%20%20%20%20model_type_dd%20%3D%20controls%5B%22model_type%22%5D%0A%20%20%20%20available_models%20%3D%20model_options%5B_backend_value%5D%0A%20%20%20%20model_type_dd.options%20%3D%20available_models%0A%20%20%20%20%23%20If%20current%20value%20is%20no%20longer%20valid%2C%20reset%20it%0A%20%20%20%20if%20model_type_dd.value%20not%20in%20available_models%3A%0A%20%20%20%20%20%20%20%20model_type_dd.value%20%3D%20list(available_models.keys())%5B0%5D%0A%0A%20%20%20%20%23%20Second%2C%20build%20the%20UI%20from%20the%20now-updated%20controls%0A%20%20%20%20tabs%20%3D%20%7B%7D%0A%20%20%20%20num_networks%3A%20int%20%3D%20n_nets.value%0A%0A%20%20%20%20for%20i%20in%20range(num_networks)%3A%0A%20%20%20%20%20%20%20%20controls%20%3D%20network_controls%5Bi%5D%0A%20%20%20%20%20%20%20%20model_type_dd%20%3D%20controls%5B%22model_type%22%5D%0A%20%20%20%20%20%20%20%20hidden_features_slider%20%3D%20controls%5B%22hidden_features%22%5D%0A%20%20%20%20%20%20%20%20value_slider%20%3D%20controls%5B%22value_slider%22%5D%0A%0A%20%20%20%20%20%20%20%20current_model%3A%20str%20%3D%20model_type_dd.value%0A%20%20%20%20%20%20%20%20ui_elements%3A%20List%5Bmo.ui.UIElement%5BAny%2C%20Any%5D%5D%20%3D%20%5Bmodel_type_dd%5D%0A%0A%20%20%20%20%20%20%20%20if%20current_model%20%3D%3D%20%22mdn%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20value_slider.label%20%3D%20%22Num%20Components%22%0A%20%20%20%20%20%20%20%20%20%20%20%20ui_elements.extend(%5Bhidden_features_slider%2C%20value_slider%5D)%0A%20%20%20%20%20%20%20%20elif%20current_model%20in%20%5B%22maf%22%2C%20%22nsf%22%2C%20%22made%22%2C%20%22ncsf%22%2C%20%22cnf%22%2C%20%22gf%22%2C%20%22sospf%22%2C%20%22naf%22%2C%20%22unaf%22%5D%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20value_slider.label%20%3D%20%22Num%20Transforms%22%0A%20%20%20%20%20%20%20%20%20%20%20%20ui_elements.extend(%5Bhidden_features_slider%2C%20value_slider%5D)%0A%20%20%20%20%20%20%20%20elif%20current_model%20in%20%5B%22mlp%22%2C%20%22resnet%22%5D%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20ui_elements.append(hidden_features_slider)%0A%0A%20%20%20%20%20%20%20%20tabs%5Bf%22Network%20%7Bi%20%2B%201%7D%22%5D%20%3D%20mo.vstack(ui_elements)%22%22%22%0A%20%20%20%20return%20(tabs%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20mo.output.append(mo.md(%22%23%23%23%20%20Base%20Setup%22))%0A%0A%20%20%20%20unique_name%20%3D%20mo.ui.text(placeholder%3D%22unique%20name%20for%20run%22%2C%20label%3D%22Name%3A%22)%0A%0A%20%20%20%20n_nets%20%3D%20mo.ui.slider(start%3D1%2C%20stop%3D6%2C%20value%3D1%2C%20label%3D%22Number%20of%20Networks%3A%22%2C%20show_value%3DTrue)%0A%20%20%20%20backend%20%3D%20mo.ui.dropdown(options%3D%5B%22lampe%22%2C%20%22sbi%22%5D%2C%20value%3D%22sbi%22%2C%20label%3D%22Backend%3A%22)%0A%20%20%20%20engine%20%3D%20mo.ui.dropdown(%0A%20%20%20%20%20%20%20%20options%3D%5B%22NPE%22%2C%20%22NLE%22%2C%20%22NRE%22%2C%20%22SNPE%22%2C%20%22SNLE%22%2C%20%22SNRE%22%5D%2C%20value%3D%22NPE%22%2C%20label%3D%22Engine%3A%22%0A%20%20%20%20)%0A%20%20%20%20stop_after_epochs%20%3D%20mo.ui.slider(%0A%20%20%20%20%20%20%20%20start%3D5%2C%20stop%3D50%2C%20value%3D20%2C%20label%3D%22Stop%20after%20Epochs%3A%20%22%2C%20show_value%3DTrue%0A%20%20%20%20)%0A%20%20%20%20learning_rate%20%3D%20mo.ui.slider(%0A%20%20%20%20%20%20%20%20steps%3Dnp.logspace(-2%2C%20-6%2C%20100)%2C%20label%3D%22Learning%20Rate%3A%22%2C%20show_value%3DTrue%0A%20%20%20%20)%0A%20%20%20%20validation_fraction%20%3D%20mo.ui.slider(%0A%20%20%20%20%20%20%20%20start%3D0%2C%20stop%3D0.30%2C%20value%3D0.10%2C%20label%3D%22Validation%20Fraction%3A%22%2C%20include_input%3DTrue%0A%20%20%20%20)%0A%20%20%20%20clip_max_norm%20%3D%20mo.ui.slider(%0A%20%20%20%20%20%20%20%20start%3D0.1%2C%20stop%3D5.0%2C%20value%3D5%2C%20label%3D%22Clip%20Max%20Norm%3A%22%2C%20include_input%3DTrue%0A%20%20%20%20)%0A%20%20%20%20training_batch_size%20%3D%20mo.ui.slider(%0A%20%20%20%20%20%20%20%20start%3D32%2C%20stop%3D128%2C%20value%3D64%2C%20label%3D%22Training%20Batch%20Size%3A%20%22%2C%20show_value%3DTrue%0A%20%20%20%20)%0A%0A%20%20%20%20ui%20%3D%20mo.vstack(%0A%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20unique_name.center()%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20mo.hstack(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mo.vstack(%5Bn_nets%2C%20backend%2C%20engine%2C%20learning_rate%5D%2C%20align%3D%22stretch%22)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20mo.vstack(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5Bstop_after_epochs%2C%20validation_fraction%2C%20clip_max_norm%2C%20training_batch_size%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20)%2C%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20)%0A%0A%20%20%20%20mo.output.append(ui)%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20backend%2C%0A%20%20%20%20%20%20%20%20clip_max_norm%2C%0A%20%20%20%20%20%20%20%20engine%2C%0A%20%20%20%20%20%20%20%20learning_rate%2C%0A%20%20%20%20%20%20%20%20n_nets%2C%0A%20%20%20%20%20%20%20%20stop_after_epochs%2C%0A%20%20%20%20%20%20%20%20training_batch_size%2C%0A%20%20%20%20%20%20%20%20unique_name%2C%0A%20%20%20%20%20%20%20%20validation_fraction%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(tabs)%3A%0A%20%20%20%20mo.output.append(mo.md(%22%23%23%23%20Network%20Configuration%22))%0A%20%20%20%20mo.output.append(mo.ui.tabs(tabs))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20backend%2C%0A%20%20%20%20clip_max_norm%2C%0A%20%20%20%20configs%2C%0A%20%20%20%20engine%2C%0A%20%20%20%20learning_rate%2C%0A%20%20%20%20n_nets%2C%0A%20%20%20%20network_controls%2C%0A%20%20%20%20stop_after_epochs%2C%0A%20%20%20%20training_batch_size%2C%0A%20%20%20%20unique_name%2C%0A%20%20%20%20validation_fraction%2C%0A)%3A%0A%20%20%20%20n_nets.value%2C%20backend.value%2C%20engine.value%2C%20stop_after_epochs.value%2C%20learning_rate.value%0A%0A%0A%20%20%20%20def%20get_configs()%20-%3E%20Dict%3A%0A%20%20%20%20%20%20%20%20%22%22%22Collects%20and%20returns%20the%20current%20configuration%20values.%22%22%22%0A%20%20%20%20%20%20%20%20config%3A%20Dict%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22n_nets%22%3A%20n_nets.value%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22backend%22%3A%20backend.value%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22engine%22%3A%20engine.value%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22learning_rate%22%3A%20np.round(learning_rate.value%2C%207)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22stop_after_epochs%22%3A%20stop_after_epochs.value%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22training_batch_size%22%3A%20training_batch_size.value%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22clip_max_norm%22%3A%20clip_max_norm.value%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22validation_fraction%22%3A%20validation_fraction.value%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22model_type%22%3A%20%5B%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22hidden_features%22%3A%20%5B%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22num_components%22%3A%20%5B%5D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22num_transforms%22%3A%20%5B%5D%2C%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20for%20_i%20in%20range(n_nets.value)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20controls%20%3D%20network_controls%5B_i%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20model_type%20%3D%20controls%5B%22model_type%22%5D.value%0A%20%20%20%20%20%20%20%20%20%20%20%20config%5B%22model_type%22%5D.append(model_type)%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20value_slider_val%20%3D%20controls%5B%22value_slider%22%5D.value%0A%20%20%20%20%20%20%20%20%20%20%20%20hidden_features_val%20%3D%20controls%5B%22hidden_features%22%5D.value%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20model_type%20%3D%3D%20%22mdn%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20config%5B%22hidden_features%22%5D.append(hidden_features_val)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20config%5B%22num_components%22%5D.append(value_slider_val)%0A%20%20%20%20%20%20%20%20%20%20%20%20elif%20model_type%20in%20%5B%22maf%22%2C%20%22nsf%22%2C%20%22made%22%2C%20%22ncsf%22%2C%20%22cnf%22%2C%20%22gf%22%2C%20%22sospf%22%2C%20%22naf%22%2C%20%22unaf%22%5D%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20config%5B%22hidden_features%22%5D.append(hidden_features_val)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20config%5B%22num_transforms%22%5D.append(value_slider_val)%0A%20%20%20%20%20%20%20%20%20%20%20%20elif%20model_type%20in%20%5B%22mlp%22%2C%20%22resnet%22%5D%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20config%5B%22hidden_features%22%5D.append(hidden_features_val)%0A%0A%20%20%20%20%20%20%20%20%23%20Clean%20up%20empty%20lists%20to%20make%20the%20table%20tidy%0A%20%20%20%20%20%20%20%20final_config%20%3D%20%7Bk%3A%20v%20for%20k%2C%20v%20in%20config.items()%20if%20v%7D%0A%20%20%20%20%20%20%20%20return%20final_config%0A%0A%0A%20%20%20%20num_nets_to_show%20%3D%20n_nets.value%0A%20%20%20%20current_configs%20%3D%20configs()%5B%3Anum_nets_to_show%5D%0A%0A%20%20%20%20%23%20Format%20the%20raw%20config%20data%20into%20the%20desired%20output%20dictionary%0A%20%20%20%20output_dict%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22name%22%3A%20unique_name.value%2C%0A%20%20%20%20%20%20%20%20%22n_nets%22%3A%20n_nets.value%2C%0A%20%20%20%20%20%20%20%20%22backend%22%3A%20backend.value%2C%0A%20%20%20%20%20%20%20%20%22engine%22%3A%20engine.value%2C%0A%20%20%20%20%20%20%20%20%22learning_rate%22%3A%20np.round(learning_rate.value%2C%207)%2C%0A%20%20%20%20%20%20%20%20%22stop_after_epochs%22%3A%20stop_after_epochs.value%2C%0A%20%20%20%20%20%20%20%20%22training_batch_size%22%3A%20training_batch_size.value%2C%0A%20%20%20%20%20%20%20%20%22clip_max_norm%22%3A%20clip_max_norm.value%2C%0A%20%20%20%20%20%20%20%20%22validation_fraction%22%3A%20validation_fraction.value%2C%0A%20%20%20%20%20%20%20%20%22model_type%22%3A%20%5Bnet%5B%22model_type%22%5D%20for%20net%20in%20current_configs%5D%2C%0A%20%20%20%20%20%20%20%20%22hidden_features%22%3A%20%5B%5D%2C%0A%20%20%20%20%20%20%20%20%22num_components%22%3A%20%5B%5D%2C%0A%20%20%20%20%20%20%20%20%22num_transforms%22%3A%20%5B%5D%2C%0A%20%20%20%20%7D%0A%0A%20%20%20%20for%20n_config%20in%20current_configs%3A%0A%20%20%20%20%20%20%20%20model_type%20%3D%20n_config%5B%22model_type%22%5D%0A%20%20%20%20%20%20%20%20if%20model_type%20in%20%5B%22mdn%22%2C%20%22mlp%22%2C%20%22resnet%22%5D%20or%20%22maf%22%20in%20model_type%20or%20%22nsf%22%20in%20model_type%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20output_dict%5B%22hidden_features%22%5D.append(n_config%5B%22hidden_features%22%5D)%0A%0A%20%20%20%20%20%20%20%20if%20model_type%20%3D%3D%20%22mdn%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20output_dict%5B%22num_components%22%5D.append(n_config%5B%22value%22%5D)%0A%20%20%20%20%20%20%20%20elif%20%22maf%22%20in%20model_type%20or%20%22nsf%22%20in%20model_type%20or%20%22made%22%20in%20model_type%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20output_dict%5B%22num_transforms%22%5D.append(n_config%5B%22value%22%5D)%0A%0A%20%20%20%20%23%20Clean%20up%20empty%20lists%20to%20make%20the%20table%20tidy%0A%20%20%20%20config%20%3D%20%7Bk%3A%20v%20for%20k%2C%20v%20in%20output_dict.items()%20if%20v%7D%0A%0A%20%20%20%20show_config%20%3D%20%7B%0A%20%20%20%20%20%20%20%20k%3A%20%22%2C%20%22.join(%5Bstr(_w)%20for%20_w%20in%20v%5D)%20if%20isinstance(v%2C%20list)%20else%20v%20for%20k%2C%20v%20in%20config.items()%0A%20%20%20%20%7D%0A%0A%0A%20%20%20%20collected_model_types%20%3D%20config%5B%22model_type%22%5D%0A%20%20%20%20collected_hidden_features%20%3D%20config%5B%22hidden_features%22%5D%0A%20%20%20%20collected_num_transforms%20%3D%20config%5B%22num_transforms%22%5D%20if%20%22num_transforms%22%20in%20config.keys()%20else%20%5B-1%5D%0A%20%20%20%20collected_num_components%20%3D%20config%5B%22num_components%22%5D%20if%20%22num_components%22%20in%20config.keys()%20else%20%5B-1%5D%0A%0A%20%20%20%20collected_model_types%20%3D%20(%0A%20%20%20%20%20%20%20%20collected_model_types%5B0%5D%20if%20len(collected_model_types)%20%3D%3D%201%20else%20collected_model_types%0A%20%20%20%20)%0A%20%20%20%20collected_hidden_features%20%3D%20(%0A%20%20%20%20%20%20%20%20collected_hidden_features%5B0%5D%20if%20len(collected_model_types)%20%3D%3D%201%20else%20collected_hidden_features%0A%20%20%20%20)%0A%20%20%20%20collected_num_transforms%20%3D%20(%0A%20%20%20%20%20%20%20%20collected_num_transforms%5B0%5D%20if%20len(collected_num_transforms)%20%3D%3D%201%20else%20collected_num_transforms%0A%20%20%20%20)%0A%20%20%20%20collected_num_components%20%3D%20(%0A%20%20%20%20%20%20%20%20collected_num_components%5B0%5D%20if%20len(collected_num_components)%20%3D%3D%201%20else%20collected_num_components%0A%20%20%20%20)%0A%0A%20%20%20%20mo.output.append(mo.ui.table(show_config%2C%20pagination%3DFalse))%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20collected_hidden_features%2C%0A%20%20%20%20%20%20%20%20collected_model_types%2C%0A%20%20%20%20%20%20%20%20collected_num_components%2C%0A%20%20%20%20%20%20%20%20collected_num_transforms%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20run_sbi_button%20%3D%20mo.ui.run_button(label%3D%22Run%20SBI%20Training%22)%0A%20%20%20%20run_sbi_button%0A%20%20%20%20return%20(run_sbi_button%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20backend%2C%0A%20%20%20%20clip_max_norm%2C%0A%20%20%20%20collected_hidden_features%2C%0A%20%20%20%20collected_model_types%2C%0A%20%20%20%20collected_num_components%2C%0A%20%20%20%20collected_num_transforms%2C%0A%20%20%20%20empirical_model_fitter%2C%0A%20%20%20%20engine%2C%0A%20%20%20%20learning_rate%2C%0A%20%20%20%20n_nets%2C%0A%20%20%20%20run_sbi_button%2C%0A%20%20%20%20stop_after_epochs%2C%0A%20%20%20%20training_batch_size%2C%0A%20%20%20%20unique_name%2C%0A%20%20%20%20validation_fraction%2C%0A)%3A%0A%20%20%20%20mo.stop(not%20run_sbi_button.value%2C%20mo.md(%22Click%20%F0%9F%91%86%20to%20run%20SBI%20training.%22))%0A%0A%20%20%20%20empirical_model_fitter.run_single_sbi(%0A%20%20%20%20%20%20%20%20n_nets%3Dn_nets.value%2C%0A%20%20%20%20%20%20%20%20backend%3Dbackend.value%2C%0A%20%20%20%20%20%20%20%20engine%3Dengine.value%2C%0A%20%20%20%20%20%20%20%20stop_after_epochs%3Dstop_after_epochs.value%2C%0A%20%20%20%20%20%20%20%20learning_rate%3Dlearning_rate.value%2C%0A%20%20%20%20%20%20%20%20hidden_features%3Dcollected_hidden_features%2C%0A%20%20%20%20%20%20%20%20num_transforms%3Dcollected_num_transforms%2C%0A%20%20%20%20%20%20%20%20num_components%3Dcollected_num_components%2C%0A%20%20%20%20%20%20%20%20model_type%3Dcollected_model_types%2C%0A%20%20%20%20%20%20%20%20training_batch_size%3Dtraining_batch_size.value%2C%0A%20%20%20%20%20%20%20%20validation_fraction%3Dvalidation_fraction.value%2C%0A%20%20%20%20%20%20%20%20clip_max_norm%3Dclip_max_norm.value%2C%0A%20%20%20%20%20%20%20%20name_append%3Dunique_name.value%20if%20unique_name.value%20else%20%22timestamp%22%2C%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
5c2d37b41eb27935de702117773fb7c50bcf4e1d1900a2765503287cfaf80178